//获取零售经理的销售提成
jQuery(document).ready(function() {
    //员工姓名id
    var ygxmField = WfForm.convertFieldNameToId("ygxm", "detail_1");

    //分公司销售任务
    var fgsxsrwField = WfForm.convertFieldNameToId("fgsxsrw", "detail_1");
    //分公司销售业绩
    var fgsxsyjField = WfForm.convertFieldNameToId("fgsxsyj", "detail_1");
     //小程序业绩
        var xcxyjField=WfForm.convertFieldNameToId("xcxyj", "detail_1");
    //完成率
    var wclField=WfForm.convertFieldNameToId("wcl", "detail_1");
    //分公司fieldid
    var fgsField=WfForm.convertFieldNameToId("fgs","detail_1");

    //操作日期
    var czrqField=WfForm.convertFieldNameToId("czrq");

    //奖金金额fielid
    var jjjeyField=WfForm.convertFieldNameToId("tcje","detail_1");
    //员工姓名改变时,触发事件
    WfForm.bindDetailFieldChangeEvent(ygxmField,
    function(id, index, value) {
        //分公司值
       var fgsVal=WfForm.getFieldValue(fgsField+"_"+index);

   //人员姓名变化时,把提成金额的值先清空
        WfForm.changeFieldValue(jjjeyField + "_" + index, {
                             value:""
                         });

        //员工姓名的值
        var ygxmVal = WfForm.getFieldValue(ygxmField + "_" + index);
          //操作日期值
           var czrqVal=WfForm.getFieldValue(czrqField);
        //根据当前完成比和部门id
        jQuery.ajax({
            async: false,
            type: 'get',
            url: "/api/weavernorth/salary/retailmess",
            data: {
                "userid": ygxmVal,
                "zdmc":"lsjl",
                 "czrq":czrqVal,
                 "fgsVal":fgsVal

            },
            success: function(data) {
                var data = JSON.parse(data);

                WfForm.changeFieldValue(fgsxsrwField + "_" + index, {
                    value: data.yrw
                });
                WfForm.changeFieldValue(fgsxsyjField + "_" + index, {
                    value: data.xlzls
                });
                      WfForm.changeFieldValue(xcxyjField + "_" + index, {
                                    value: data.xcxxszls
                                      });

            }
        });

    });



        //分公司改变时,触发事件
        WfForm.bindDetailFieldChangeEvent(fgsField,
        function(id, index, value) {
     //员工姓名的值
          var ygxmVal = WfForm.getFieldValue(ygxmField + "_" + index);

       //人员姓名变化时,把提成金额的值先清空
            WfForm.changeFieldValue(jjjeyField + "_" + index, {
                                 value:""
                             });

              //操作日期值
               var czrqVal=WfForm.getFieldValue(czrqField);
            //根据当前完成比和部门id
            jQuery.ajax({
                async: false,
                type: 'get',
                url: "/api/weavernorth/salary/retailmess",
                data: {
                    "userid": ygxmVal,
                    "zdmc":"lsjl",
                     "czrq":czrqVal,
                     "fgsVal":value

                },
                success: function(data) {
                    var data = JSON.parse(data);

                    WfForm.changeFieldValue(fgsxsrwField + "_" + index, {
                        value: data.yrw
                    });
                    WfForm.changeFieldValue(fgsxsyjField + "_" + index, {
                        value: data.xlzls
                    });
                       WfForm.changeFieldValue(xcxyjField + "_" + index, {
                                                        value: data.xcxxszls
                                                          });

                }
            });

        });



    //当完成率改变时,需要查询提成金额
    WfForm.bindDetailFieldChangeEvent(wclField,
    function(id, index, value) {


     //分公司值
       var fgsVal=WfForm.getFieldValue(fgsField+"_"+index);

     //完成率值
     var wclVal= WfForm.getFieldValue(wclField + "_" + index);
      //操作日期值
            var czrqVal=WfForm.getFieldValue(czrqField);
    //分公司任务
    var fgsrwVal=WfForm.getFieldValue(fgsxsrwField + "_" + index);
             //根据完成比和部门id
             jQuery.ajax({
                 async: false,
                 type: 'get',
                 url: "/api/weavernorth/salary/getTcje",
                 data: {
                     "fgsVal": fgsVal,
                    "wclVal":wclVal,
                    "fgsrwVal":fgsrwVal,
                    "czrqVal":czrqVal
                 },
                 success: function(data) {

                     var data = JSON.parse(data);

                     WfForm.changeFieldValue(jjjeyField + "_" + index, {
                         value:data
                     });


                 }
             });

    });
});

